package com.cc.mall.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Data
@ToString
@ApiModel("订单")
public class OrderVo implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 订单id
     */
    @ApiModelProperty("订单id")
    private Long id;
    /**
     * 订单类型
     * 1.线上
     * 2.线下
     */
    @ApiModelProperty("订单类型1.线上2.线下")
    private Integer orderType;
    /**
     * 用户id
     */
    @ApiModelProperty("用户id")
    private Long uid;
    /**
     * 收货地址id
    private Long raid;*/
    /**
     * 状态0待付款1待发货2待收货3已收货
     */
    @ApiModelProperty("收货状态0待付款1待发货2待收货3已收货")
    private Integer status;
    /**
     * 创建时间
     */
    @ApiModelProperty("订单创建时间")
    private Date createtime;
    /**
     * 该订单的总价格
     */
    @ApiModelProperty("订单总价格")
    private BigDecimal totalAmount;
    /**
     * 该订单的实际应付价格
     */
    @ApiModelProperty("该订单的实际应付价格")
    private BigDecimal amountsPayable;
    /**
     * 该订单下的具体订单详情
     */
    @ApiModelProperty("该订单下的具体订单详情")
    private List<OrderItem> orderItemList = new ArrayList<>();

    public BigDecimal getTotalAmount(){
        BigDecimal sum = new BigDecimal("0");
        for (OrderItem orderItem : this.orderItemList) {
            if(orderItem.getCheck() && orderItem.getTotalPrice()!=null){
                sum = sum.add(orderItem.getTotalPrice());
            }
        }
        return sum;
    }
}
